package com.abe.bathsystem.widget.dialog;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.widget.EditText;
import android.widget.TextView;

import net.yet.campusdev.R;

import com.abe.bathsystem.entity.http.HttpBathPosStateEntity;
import com.abe.bathsystem.widget.OnOperateListener;
import com.abe.libcore.utils.normal.ToastUtils;

public class LoginQuickDialog extends BaseDialog {

    private DialogContract.OnLoginListener listener;
    private String phone;
    private HttpBathPosStateEntity posStateEntity;

    public LoginQuickDialog(Context context, OnOperateListener operateListener, String phone, HttpBathPosStateEntity posStateEntity) {
        super(context, operateListener);
        if (TextUtils.isEmpty(phone)) this.dismiss();
        this.phone = phone;
        this.posStateEntity = posStateEntity;
    }

    public LoginQuickDialog(Context context, String phone, HttpBathPosStateEntity posStateEntity) {
        super(context);
        if (TextUtils.isEmpty(phone)) this.dismiss();
        this.phone = phone;
        this.posStateEntity = posStateEntity;
    }

    public void setListener(DialogContract.OnLoginListener listener) {
        this.listener = listener;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.item_view_v3_user_quick_login);
        TextView itemTxtUserPhone = findViewById(R.id.item_txt_user_phone);
        itemTxtUserPhone.setText(phone);
        final EditText itemUserPass = findViewById(R.id.item_user_pass);
        findViewById(R.id.item_user_login).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String password = itemUserPass.getText().toString().trim();
                if (TextUtils.isEmpty(password)) {
                    ToastUtils.show(R.string.hint_input_password);
                    return;
                }
                if (listener != null) {
                    listener.onLoginUser(phone, password, posStateEntity);
                } else {
                    ToastUtils.show("请绑定回调监听");
                }
                dismiss();
            }
        });
    }
}
